<template>
    <div style="display: block">
        <el-row>

            <el-col :span="6">
                <el-form ref="formInline" :model="formInline" :rules="ruleInline" style="float: left">
                    <el-form-item prop="user" style="float: left">
                        <el-input type="text" v-model="formInline.user" placeholder="文章名字" style="float: left">文章名字</el-input>

                    </el-form-item>

                    <el-form-item style="float: left">
                        <el-button @click="getArticles" style="float: left;margin-left: 10px;" type="primary">查询</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
        <el-table
                :data="data1"
                border
                style="width: 100%;text-aligin:center">
            <el-table-column
                    type="index"
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="名称"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="desc"
                    label="描述"
                    width="120">
            </el-table-column>
            <el-table-column
                    prop="pic"
                    label="缩略图"
                    width="120"
            >
            </el-table-column>
            <el-table-column
                    prop="doc"
                    label="详细资料"
                    >
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    width="150">
                <template slot-scope="scope">
                    <el-button type="text" @click="handleClick(scope)" size="small">查看</el-button>
                    <el-button type="text" @click="handleEdit(scope)"  size="small">编辑</el-button>
                    <el-button type="text" @click="handleDelete(scope)" size="small">刪除</el-button>

                </template>
            </el-table-column>
        </el-table>
        <div class="block">
            <el-pagination
                    layout="prev, pager, next"
                    :total="hardwareCount"
            >
            </el-pagination>
        </div>

        <el-dialog
                title="提示"
                :visible.sync="dialogVisible"
                width="30%"
                :before-close="handleClose">
            <span>这是一段信息</span>
            <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
        </span>
        </el-dialog>
    </div>
</template>

<script>
    import Message from "element-ui/lib/message";
    import axios from "@/api/ajax.js";
    import Cookie from "js-cookie";
    import Const from "@/const.js";
    export default {
        name: "hardware_manager",
        components: {
        },
        data: () => {
            return {
                hardwareCount:0,
                data1:[],
                data2:[],
                formInline: {
                    dockname: '',
                    type: ''
                },
                limit:10,
                offset :0,
                is_public: 0,
            };
        },
        methods: {
            handleDelete(row) {
                console.log(row);
                axios.delete('hardware?name=' + row.row.name, {}).then(
                    result => {
                        if (result.data.Status === 0){
                            Message.success("删除成功");
                        }
                    }
                )
            },
            getHardwares(){
                axios.get('/hardware?limit=' + this.limit + '&offset='  + this.offset,{
                }).then(response=> {
                        this.data1 = [];
                        if (response.data.Status === 0)
                        {
                            let j = 0;
                            if(response.data.Data != null){
                                for(let len= response.data.Data.length; j < len; j++) {
                                    console.log(j,response.data.Data[j])
                                    this.data2.push(response.data.Data[j]);
                                    this.data1.push(response.data.Data[j]);
                                }
                            }
                        }
                    }
                ).catch(reason => {
                    Message.error("网络错误:" + reason);
                });
            }
        },
        created() {
            this.getHardwares();
        },
        beforeCreate() {

        }
    };
</script>
<style >
    .container {
        width: 100%;
    }
    .md-text {
        font-size: 12px;
        width: 100%;
    }
    .md-body {
        width: 100%;
        margin-left: 20px;
    }
    .md-text1 {
        font-size: 15px;
        margin-top: 10px;
    }
    .mavonEditor {
        width: 100%;
        height: 800px;
    }
</style>
